/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package LiveReservations.gui.control;

import LiveReservations.gui.RegisterUI;
import LiveReservations.model.clients.RegisteredClient;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import javax.naming.NamingException;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import viewManager.AbstractViewManager;

/**
 *
 * @author Aeon
 */
public class RegisterUIManager extends AbstractViewManager implements ActionListener {

    private JButton buttonOk;
    private JButton buttonCancel;
    private JPasswordField passwordFieldPassword;
    private JPasswordField passwordFieldRPassword;
    private JTextField textFieldFname;
    private JTextField textFieldLname;
    private JTextField textFieldTel;
    private JTextField textFieldUsername;
    private RegisteredClient newRegisteredClient;
    private char[] password;
    private char[] passwordR;

    public RegisterUIManager() {

        super.contentView = new RegisterUI();
    }

    @Override
    protected void initComponents() throws NamingException {
        buttonOk = (JButton) componentHolder.getComponentByName("buttonOk");
        buttonOk.addActionListener(this);
        buttonCancel = (JButton) componentHolder.getComponentByName("buttonCancel");
        passwordFieldPassword = (JPasswordField) componentHolder.getComponentByName("passwordFieldPassword");
        passwordFieldRPassword = (JPasswordField) componentHolder.getComponentByName("passwordFieldRPassword");
        textFieldFname = (JTextField) componentHolder.getComponentByName("textFieldFName");
        textFieldLname = (JTextField) componentHolder.getComponentByName("textFieldLname");
        textFieldTel = (JTextField) componentHolder.getComponentByName("textFieldTel");
        textFieldUsername = (JTextField) componentHolder.getComponentByName("textFieldUsername");
    }

    @Override
    protected void manageComponents() {

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(contentView, "Works");
    }

    public RegisteredClient getNewRegisteredClient() {

        String Fname = textFieldFname.getText();
        String Lname = textFieldLname.getText();
        String Tel = textFieldTel.getText();
        String Username = textFieldUsername.getText();
        char[] Password = passwordFieldPassword.getPassword();

        newRegisteredClient.setName(Fname);
        newRegisteredClient.setSurname(Lname);
        newRegisteredClient.setTelephone(Tel);
        newRegisteredClient.setUsername(Username);
        newRegisteredClient.setPassword(Password);

        return newRegisteredClient;
    }

    public boolean isPasswordEqual(char[] password, char[] passwordR) {
        return Arrays.equals(password, passwordR);
    }
}
